package GUI;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.border.LineBorder;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;

import javax.swing.JButton;

import MessagePacks.MessagePack;
import MessagePacks.UpdatePack;

import java.awt.event.ActionListener;

/**
 *@author Juan Alapin - 324507516
 *@author Giora Yaffe - 036551281
 *@author Shachar Gritzman - 300174026
 *@author Nir Porat - 021515580
*/

public class TesterScreen extends MasterGUI {
	
	private static final long serialVersionUID = 1L;
	private JButton btnTimeExtensionRequest;
	private JButton btnConfirmTesting;
	private JButton btnReportFailDetails;
	private JPanel panel_1;
	private MainGUI mainGui;
	private UpdatePack updatePhs,time;
	
	
	public TesterScreen(MainGUI mainGui) {
		super(mainGui);
		this.mainGui=mainGui;
		
		
		panel_1 = new JPanel();
		panel_1.setBorder(new LineBorder(new Color(0, 0, 0)));
		panel_1.setBounds(0, 40, 176, 201);
		getContentPane().add(panel_1);
		panel_1.setLayout(null);
		
		setBtnTimeExtensionRequest();
		setBtnConfirmTesting(btnConfirmTesting);
		setBtnReportFailDetails( btnReportFailDetails);
		

		
		JPanel panel = new JPanel();
		panel.setBounds(0, 0, 884, 40);
		getContentPane().add(panel);
		
		JLabel lblTesterMenu = new JLabel("Tester Menu");
		lblTesterMenu.setFont(new Font("Dialog", Font.BOLD, 16));
		panel.add(lblTesterMenu);

	}
	
	public JButton getBtnTimeExtensionRequest() {
		return btnTimeExtensionRequest;
	}


	public void setBtnTimeExtensionRequest() {
		btnTimeExtensionRequest = new JButton("Time Extension Request");
		btnTimeExtensionRequest.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				close();
				TimeExtensionRequest TE = new TimeExtensionRequest(mainGui);
				TE.setVisible(true);
			}
		});
		btnTimeExtensionRequest.setBounds(10, 79, 156, 23);
		panel_1.add(btnTimeExtensionRequest);
	}


	public JButton getBtnConfirmTesting() {
		return btnConfirmTesting;
	}


	public void setBtnConfirmTesting(JButton btnConfirmTesting) {
		btnConfirmTesting = new JButton("Confirm Testing");
		btnConfirmTesting.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				updatePhase5();
				updateTimeForLevel5();
				JOptionPane.showMessageDialog(serverGUI.mainframe,"Phase 4 completed.");
			}
		});
		btnConfirmTesting.setBounds(10, 11, 156, 23);
		panel_1.add(btnConfirmTesting);
	}


	public JButton getBtnReportFailDetails() {
		return btnReportFailDetails;
	}

	public void setBtnReportFailDetails(JButton btnReportFailDetails) {
		btnReportFailDetails = new JButton("Report Testing Fails");
		btnReportFailDetails.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				close();
				TesterFailReport TFR = new TesterFailReport(mainGui);
				TFR.setVisible(true);
			}
		});
		btnReportFailDetails.setBounds(10, 45, 156, 23);
		panel_1.add(btnReportFailDetails);
	}
	
	public void updatePhase5(){
		updatePhs = new UpdatePack(MessagePack.updatePhase);
		updatePhs.setPhaseNum(5);
		updatePhs.setProcId(mainGui.process.getprocessID());
	//	updatePhs.setResponOk(1);
		mainGui.client.handleMessageFromClientUI(updatePhs);
		
	}
	
	public void updateTimeForLevel5() {
		time= new UpdatePack(MessagePack.updateleveltime);
		time.setTime(0);
		time.setPhaseNum(5);
		time.setProcId(mainGui.process.getprocessID());
		mainGui.client.handleMessageFromClientUI(time);
	}
}
